<template>
    <h3>公告信息表</h3>
    公告标题:<input type="rext" v-model="Iname"/>
    <input type="button" value="查询" class="btn btn-info" @click="getInfo"/>&emsp;&emsp;
    <input type="button" value="导出公告信息" class="btn btn-info" @click="ExportInfo"/>
        <table class="table table-bordered" border="1">
        <thead>
            <tr>
                <td>公告编号</td>
                <td>公告标题</td>
                <td>公告内容</td>
                <td>公告类型</td>
                <td>操作</td>
            </tr>
        </thead>
        <tbody>
            <tr v-for="item in info">
                <td>{{ item.info_Id }}</td>
                <td>{{ item.info_Title }}</td>
                <td>{{ item.info_string }}</td>
                <td>{{ item.type_Name }}</td>
                <td>
                </td>
            </tr>
        </tbody>
    </table>
</template>

<script setup lang="ts">
import axios from 'axios';
import { ref,onMounted } from 'vue';
import { useRouter } from 'vue-router';

//创建生命周期钩子
onMounted(()=>{
    getInfo();
})
//创建响应式数据用于加载公告信息
const info=ref([{
    "info_Id": 0,
    "info_Title": "string",
    "info_string": "string",
    "info_Type": 0,
    "type_Name": "string"
}])
//查询条件
const Iname=ref("")
//加载公告信息
const getInfo=()=>{
    axios.get("https://localhost:7283/api/Info/ShowInfo?Iname="+Iname.value)
    .then(res=>{
        info.value=res.data
    })
    .catch(error=>{
        alert(error)
    })
}
//路径
const fpath=ref("C:/Users/PC/Desktop/李亚涛0106月考/Info.xlsx")
//导出公告信息
const ExportInfo=()=>{
    axios.post("https://localhost:7283/api/Info/ExportFile?FPath="+fpath.value
    )
    .then(res=>{
        if(res.data>0){
            alert("导出成功")
        }
    })
    .catch(error=>{
        alert(error)
    })
}

</script>